package com.kinyx.framework.processor;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

import javax.annotation.processing.ProcessingEnvironment;

/**
 * 上下文环境
 */
public final class Context {

	private final ProcessingEnvironment processingEnvironment;
	private Logger logger;

	public Context(final ProcessingEnvironment processingEnvironment) {
		this.processingEnvironment = processingEnvironment;
		this.logger = new Logger(processingEnvironment.getMessager());
	}

	public ProcessingEnvironment getProcessingEnvironment() {
		return this.processingEnvironment;
	}

	public Logger getLogger() {
		return this.logger;
	}

	/**
	 * key：唯一标识，如TypeElement类全名。
	 * value：包装过的Element
	 */
	private final Map<String, ElementWrapper> elements = new HashMap<>();
	public Collection<ElementWrapper> getElements() { return this.elements.values(); }
	public boolean containsElement(final String id) { return this.elements.containsKey(id); }
	public void cacheElement(final String id, final ElementWrapper element) { this.elements.put(id, element); }

}
